<template>
  <div class="main">
    <!-- <h3>任务工作管理</h3> -->
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span
          ><el-row :gutter="10" class="mb8">
            <el-col v-for="item in statusBtns" :key="item.sort" :span="1.5">
              <el-button
                :type="item.type"
                plain
                :icon="item.icon"
                size="mini"
                @click="lookSearch(item.value)"
                >{{ item.label }}</el-button
              >
            </el-col>
            <el-col :span="1.5">
              <el-button
                type="primary"
                plain
                size="mini"
                v-if="statusBtns.length>0"
                @click="lookData()"
                >所有</el-button
              >
            </el-col>
          </el-row></span>
      </div>
      <div class="text item">
        <template>
          <el-table :data="tableData" border style="width: 100%">
            <el-table-column
              fixed
              type="index"
              label="序号"
              width="50"
              align="center"
            >
            </el-table-column>
            <el-table-column prop="projectName" label="项目名称" align="center">
            </el-table-column>
            <el-table-column prop="workName" label="任务名称" align="center">
            </el-table-column>
            <el-table-column prop="workType" label="任务类别" width="120" align="center" :formatter="typeFmt">
            </el-table-column>
            <el-table-column prop="workDetail" label="任务内容" align="center">
            </el-table-column>            
            <el-table-column prop="manHour" label="预计工时" align="center">
            </el-table-column>
            <el-table-column prop="useHour" label="实际工时" align="center">
            </el-table-column>
            <el-table-column prop="workStatus" label="当前状态" align="center" :formatter="statusFmt">
            </el-table-column>

            <el-table-column label="操作" width="200" align="center">
              <template slot-scope="scope">
                <el-button
                  @click="handleClick(scope.row.taskId)"
                  type="primary"
                  size="small"
                  plain
                  v-hasPermi="['system:work:detail']"
                  >查看详情</el-button
                >
              </template>
            </el-table-column>
          </el-table>
          <pagination
            v-show="total > 0"
            :total="total"
            :page.sync="queryParams.pageNum"
            :limit.sync="queryParams.pageSize"
            @pagination="getList"
          />
        </template>
      </div>
    </el-card>
  </div>
</template>

<script>
import {
  // getWork,
  listByEvaluator,
  workStatusMap,
  taskTypesMap,
} from "@/api/system/work";
export default {
  components: {
  },
  data() {
    return {
      tableData: [],
      // 查询按钮
      statusBtns: [{label:'待执行', value:'assigned', sort:0},
      {label:'已执行', value:'executed', sort:1},
      {label:'审核通过', value:'checked', sort:2},
      {label:'审核不通过', value:'rejected', sort:3},
      {label:'已完成', value:'evaluated', sort:4}
      ],
      //总条数
      total: 0,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        roleName: undefined,
        roleKey: undefined,
        workStatus: ''
      },
      workStatus:{},
      taskTypes:{}
    };
  },
  created() {
    this.init();
  },
  methods: {
    // 获取本周，上周，本月，上月的起止日期
    // 获取本周，上周，本月，上月的起止日期

    init() {
      workStatusMap().then(res=>{
        this.workStatus = res.data;
      });
      taskTypesMap().then(res=>{
        this.taskTypes = res.data;
      });
      this.queryParams.workStatus='';
      listByEvaluator(this.addDateRange(this.queryParams, this.dateRange)).then(
        res => {
          // console.log(res);
          if (res.code == 200) {
            // this.$message.success(res.msg);
            this.total = res.total;
            this.tableData = res.rows;
          } else {
            this.$message.error(res.msg);
          }
        }
      );
    },

    statusFmt(row, column, value){
      // let statusEnum = {'created':'待指派','dispatched':'待分配','assigned':'待执行','executing':'执行中',
      // 'executed':'待审核','checked':'待评价','scored':'已评价'};
      // return statusEnum[value];
      return this.workStatus[value];
    },
    typeFmt(row, column, value){
      // let typeEnum = {'survey':'需求调研','analysis':'待分配','assigned':'待执行','executing':'执行中',
      //   'executed':'待审核','checked':'待评价','scored':'已评价'};
      // return typeEnum[value];
      return this.taskTypes[value];
    },
    getList() {
      this.loading = true;
      this.init();
    },
    lookSearch(status) {
      // console.log(dictValue);
      this.queryParams.workStatus = status;
      listByEvaluator(this.addDateRange(this.queryParams, this.dateRange)).then(res => {
        // console.log(res);
        if (res.code == 200) {
          // this.$message.success(res.msg);
          this.total = res.total;
          this.tableData = res.rows;
        } else {
          this.$message.error(res.msg);
        }
      });
    },
    lookData() {
      this.init();
    },
    handleClick(workId) {
      // console.log(row.taskId);
      this.$router.push({
        path: "/work/detail",
        query: { workId }
      });
    },
  }
};
</script>

<style>
.text {
  font-size: 14px;
}

.item {
  margin-bottom: 18px;
}

.clearfix:before,
.clearfix:after {
  display: table;
  content: "";
}
.clearfix:after {
  clear: both;
}

.box-card {
  width: 100%;
}
</style>
